--//Config.lua
require("base.class")
--require("basepropSet");
--//require("base/Object")
------------------ config set ----------------------
----- maps config
MAP_CONFIG_FILE = "maps.xml";
--the fields name of maps.xml
MapInfo = {};
MapInfo.ID = "id";
MapInfo.Name = "name";
MapInfo.Load_Cls = "loadcls"
MapInfo.Save = "save";
MapInfo.FindPath= "findpath"
MapInfo.MapFile = "mapfile";
MapInfo.DstFile = "dstfile";
MapInfo.UpdateRate = "updaterate"

----- npc destribute info
DstInfo = {};
DstInfo.Type = "id";
DstInfo.X = "x";
DstInfo.Y = "y";
DstInfo.Dir ="dir";
DstInfo.Patrol ="patrol";
DstInfo.Rate = "rate"
DstInfo.Scope = "scope"


--/************** PropSets info ********************/
--PROPERTY_CONFIG_FILE = "property.xml";

--[[
Config = class();

function Config:__init()
	local mapInfos = Config.parseMapInfo(MAP_CONFIG_FILE);
	---------------------------
	-- getMapInfo
	--@mapId:	map id
	---------------------------
	self.getMapInfo = function(mapId)
		if mapId then
			return mapInfos[mapId];
		else
			return nil;
		end
	end
end

function Config.parseMapInfo(configFile)
	local tRet = {};
	--load scenes config file
	local mapInfosRoot = ParseConfigFile(configFile);
	--//--LLogger.debug("mapInfos:"..T2Str(mapInfosRoot));
	--//get the map node
	for key in pairs(mapInfosRoot) do
		local mapInfos = mapInfosRoot[key];
		--LLogger.debug("mapInfos"..T2Str(mapInfos));
		for mapKey in pairs(mapInfos) do
			if string.find(mapKey, "map") then
				local mapInfo = mapInfos[mapKey];
				--LLogger.debug("mapInfo"..T2Str(mapInfo));
				local map = {};
				for attrKey in pairs(mapInfo) do
					map[attrKey] = mapInfo[attrKey];
				end
				local id = tonumber(map[MapInfo.ID]);
				tRet[id] = map;
			end
		end
	end
	--LLogger.debug("ParseMapInfo return :"..T2Str(tRet));
	return tRet;
end
--]]

--[[
function Config.parseNpcInfo(configFile)
	local tRet = {};
	--load npc schema file
	local npcInfos = ParseConfigFile(configFile);
	for _, npcInfo in ipairs(npcInfos) do
		local id = npcInfo[NPCInfo.ID];
		tRet[id] = npcInfo;
		--LLogger.debug(string.format("self._npcInfos.insert(%d,%s)", id, T2Str(npcInfo)));
	end
	--//--LLogger.debug("ParseNPCInfo return :"..T2Str(tRet));
	return tRet;
end
--]]

--[[
function Config.parseMaterialInfo(configFile)
	local tRet = {};
	--//load material schema file
	local materialInfos = ParseConfigFile(configFile);
	for _, materialInfo in ipairs(materialInfos) do
		local id = materialInfo[MaterialInfo.ID];
		tRet[id] = materialInfo;
	end
	--//--LLogger.debug("ParseMaterialInfo return :"..T2Str(tRet));
	return tRet;
end
--]]

--[[
function Config.parseDstInfo(configFile)
	--//load destribute info file
	local tRet = {};
	local destInfosRoot = ParseConfigFile(configFile);
	for key in pairs(destInfosRoot) do
		local destInfos = destInfosRoot[key];
		for destKey in pairs(destInfos) do
			local destInfo = destInfos[destKey];
			table.insert(tRet, destInfo);
		end
	end
	return tRet;
end
--]]

--[[
function Config.parseTaskInfo(configFile)
	--LLogger.debug("parse configFile = "..configFile);
	local taskInfos = ParseConfigFile(configFile);
	--LLogger.debug("taskInfos = "..T2Str(taskInfos));
end
--]]

--[[
function Config.instance()
	if Config._instance then return Config._instance; end
	Config._instance = Config();
	--LLogger.debug(table2str(SceneMgr._instance))
	return Config._instance;
end
--]]

--//test code
--//Config.parsePropertyInfo()

--Logger.warn("load config module!!!")

